package com.qlk.odcinterface.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.qlk.odcinterface.domain.PmsProductPromotionChannel;
import com.qlk.odcinterface.domain.query.PmsProductPromotionChannelQuery;
import com.qlk.odcinterface.manager.PmsProductPromotionChannelManager;
import com.qlk.odcinterface.service.PmsProductPromotionChannelService;
import com.qlk.odcinterface.utils.exceptions.ExistedException;
import com.qlk.common.utils.page.PageUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.perf4j.aop.Profiled;
 
/**
 * PmsProductPromotionChannelService接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 13:22:58
 * 
 */
@Service
public class PmsProductPromotionChannelServiceImpl implements PmsProductPromotionChannelService {

    /** LOG */
    private static final Log LOG = LogFactory.getLog(PmsProductPromotionChannelServiceImpl.class);

    @Autowired
    private PmsProductPromotionChannelManager pmsProductPromotionChannelManager;

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionChannelService.batchInsert")
    public boolean insert(List<PmsProductPromotionChannel> pmsProductPromotionChannelList) {
        boolean resultFlag = false;
        try {
            if (CollectionUtils.isNotEmpty(pmsProductPromotionChannelList)) {
                resultFlag = pmsProductPromotionChannelManager.insert(pmsProductPromotionChannelList);
            } else {
                LOG.warn("PmsProductPromotionChannelServiceImpl#batchInsert failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionChannelServiceImpl#batchInsert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionChannelService.insert")
    public boolean insert(PmsProductPromotionChannel pmsProductPromotionChannel) {
        boolean resultFlag = false;
        try {
            if (null != pmsProductPromotionChannel) {
                if (pmsProductPromotionChannelManager.exist(pmsProductPromotionChannel)) {
                    throw new ExistedException();
                }
                resultFlag = pmsProductPromotionChannelManager.insert(pmsProductPromotionChannel);
            } else {
                LOG.warn("PmsProductPromotionChannelServiceImpl#insert failed, param is illegal.");
            }
        } catch (ExistedException e) {
            LOG.warn("PmsProductPromotionChannelServiceImpl#insert failed, pmsProductPromotionChannel has existed.");
            throw e;
        } catch (Exception e) {
            LOG.error("PmsProductPromotionChannelServiceImpl#insert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionChannelService.update")
    public boolean update(PmsProductPromotionChannel pmsProductPromotionChannel) {
        boolean resultFlag = false;
        try {
            if (null != pmsProductPromotionChannel && null != pmsProductPromotionChannel.getId()) {
                resultFlag = pmsProductPromotionChannelManager.update(pmsProductPromotionChannel);
            } else {
                LOG.warn("PmsProductPromotionChannelServiceImpl#update failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionChannelServiceImpl#update has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionChannelService.queryPmsProductPromotionChannelList")
    public List<PmsProductPromotionChannel> queryPmsProductPromotionChannelList(PmsProductPromotionChannelQuery queryBean) {
        List<PmsProductPromotionChannel> pmsProductPromotionChannelList = null;
        try {
            pmsProductPromotionChannelList = pmsProductPromotionChannelManager.queryPmsProductPromotionChannelList(queryBean);
        } catch (Exception e) {
            LOG.error("PmsProductPromotionChannelServiceImpl#queryPmsProductPromotionChannelList has error.", e);
        }
        return pmsProductPromotionChannelList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionChannelService.queryPmsProductPromotionChannelListWithPage")
    public List<PmsProductPromotionChannel> queryPmsProductPromotionChannelListWithPage(PmsProductPromotionChannelQuery queryBean, PageUtil pageUtil) {
        List<PmsProductPromotionChannel> pmsProductPromotionChannelList = null;
        try {
            pmsProductPromotionChannelList = pmsProductPromotionChannelManager.queryPmsProductPromotionChannelListWithPage(queryBean, pageUtil);
        } catch (Exception e) {
            LOG.error("PmsProductPromotionChannelServiceImpl#queryPmsProductPromotionChannelListWithPage has error.", e);
        }
        return pmsProductPromotionChannelList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionChannelService.delete")
    public boolean delete(PmsProductPromotionChannel pmsProductPromotionChannel) {
        boolean resultFlag = false;
        try {
            if (null != pmsProductPromotionChannel && null != pmsProductPromotionChannel.getId()) {
                resultFlag = pmsProductPromotionChannelManager.delete(pmsProductPromotionChannel);
            } else {
                LOG.warn("PmsProductPromotionChannelServiceImpl#delete param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionChannelServiceImpl#delete has error.", e);
        }
        return resultFlag;
    }
    @Profiled(tag = "PmsProductPromotionChannelService.deletePmsProductPromotionChannel")
    public boolean deletePmsProductPromotionChannel(PmsProductPromotionChannel pmsProductPromotionChannel) {
        boolean resultFlag = false;
        try {
            if (null != pmsProductPromotionChannel && null != pmsProductPromotionChannel.getId()) {
                resultFlag = pmsProductPromotionChannelManager.deletePmsProductPromotionChannel(pmsProductPromotionChannel);
            } else {
                LOG.warn("PmsProductPromotionChannelServiceImpl#delete param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionChannelServiceImpl#deletePmsProductPromotionChannel has error.", e);
        }
        return resultFlag;
    }
    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionChannelService.batchDelete")
    public boolean delete(PmsProductPromotionChannel[] pmsProductPromotionChannels) {
        boolean resultFlag = false;
        try {
            if (null != pmsProductPromotionChannels && pmsProductPromotionChannels.length > 0) {
                resultFlag = pmsProductPromotionChannelManager.delete(pmsProductPromotionChannels);
            } else {
                LOG.warn("PmsProductPromotionChannelServiceImpl#batchDelete failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionChannelServiceImpl#batchDelete has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsProductPromotionChannelService.getPmsProductPromotionChannelById")
    public PmsProductPromotionChannel getPmsProductPromotionChannelById(Integer id) {
        PmsProductPromotionChannel pmsProductPromotionChannel = null;
        try {
            if (null != id) {
                pmsProductPromotionChannel = pmsProductPromotionChannelManager.getPmsProductPromotionChannelById(id);
            } else {
                LOG.warn("PmsProductPromotionChannelServiceImpl#getPmsProductPromotionChannelById failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsProductPromotionChannelServiceImpl#getPmsProductPromotionChannelById has error.", e);
        }
        return pmsProductPromotionChannel;
    }
}

